/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BL;

/**
 *
 * @author DarkIaspis
 */
public class SumVector {
    
    public static double perform(double[] a){
        if(a.length==1) return new Double(a[0]);
        int halfSize=(int) java.lang.Math.floor(a.length/2);
        double[] ret;
        if(a.length%2==1){
            ret = new double[halfSize+1];
            for(int i=0; i<halfSize; i++) ret[i] = a[2*i]+a[2*i+1];
            ret[halfSize]=a[a.length-1];

        }
        else{
            ret = new double[halfSize];
            for(int i=0; i<halfSize; i++) ret[i] = a[2*i]+a[2*i+1];
        }
        return perform(ret);
    }
    
}
